home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / fax / src / faxstat / SendStatus.c++ < prev    next >
C/C++ Source or Header  |  1994-08-01  |  4KB  |  135 lines

  1. /*    $Header: /usr/people/sam/fax/faxstat/RCS/SendStatus.c++,v 1.12 1994/02/28 14:17:19 sam Rel $ */
  2. /*
  3.  * Copyright (c) 1990, 1991, 1992, 1993, 1994 Sam Leffler
  4.  * Copyright (c) 1991, 1992, 1993, 1994 Silicon Graphics, Inc.
  5.  *
  6.  * Permission to use, copy, modify, distribute, and sell this software and 
  7.  * its documentation for any purpose is hereby granted without fee, provided
  8.  * that (i) the above copyright notices and this permission notice appear in
  9.  * all copies of the software and related documentation, and (ii) the names of
  10.  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  11.  * publicity relating to the software without the specific, prior written
  12.  * permission of Sam Leffler and Silicon Graphics.
  13.  * 
  14.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  15.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  16.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  17.  * 
  18.  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  19.  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  20.  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  21.  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
  22.  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
  23.  * OF THIS SOFTWARE.
  24.  */
  25. #include <string.h>
  26. #include <time.h>
  27. #include <ctype.h>
  28.  
  29. #include "SendStatus.h"
  30.  
  31. FaxSendStatus::FaxSendStatus()
  32. {
  33.    isLocked = FALSE;
  34.    isSendAt = FALSE;
  35. }
  36. FaxSendStatus::~FaxSendStatus() {}
  37.  
  38. int
  39. FaxSendStatus::compare(const FaxSendStatus* other) const
  40. {
  41.     int c = isLocked - other->isLocked;
  42.     if (c == 0)
  43.     c = dts.compare(&other->dts);
  44.     if (c == 0)
  45.     c = tts.compare(&other->tts);
  46.     if (c == 0)
  47.     c = sender.compare(&other->sender);
  48.     if (c == 0)
  49.     c = number.compare(&other->number);
  50.     return c;
  51. }
  52.  
  53. #define nextTag(s, what)                    \
  54.     cp = tag; tag = strchr(cp, ':'); if (!tag) { what; }    \
  55.     s.append(cp, tag-cp);                    \
  56.     for (tag++; isspace(*tag); tag++);
  57. fxBool
  58. FaxSendStatus::parse(const char* tag)
  59. {
  60.     const char* cp;
  61.  
  62.     nextTag(jobname, return (FALSE));
  63.     nextTag(sender, return (FALSE));
  64.     nextTag(tts, return (FALSE));
  65.     nextTag(number, return (FALSE));
  66.     nextTag(modem, return (FALSE));
  67.     if (!isSendAt) {
  68.     status = tag;
  69.     isLocked = (tts == "locked");
  70.     if (*tag == '\0')
  71.         status = isLocked ? "Being processed" : "Queued and waiting";
  72.     if (!isLocked && tts != "asap") {
  73.         dts = tts.cut(0, 10);
  74.         /*
  75.          * The server sends ':''s as '.'s to simplify parsing.
  76.          * Now that we're done parsing, change them back.
  77.          */
  78.         tts.remove(0);        // leading blank
  79.         tts[2] = ':';
  80.         tts[5] = ':';
  81.     }
  82.     } else
  83.     status = "submitted to at and waiting";
  84.     return (TRUE);
  85. }
  86. #undef nextTag
  87.  
  88. void
  89. FaxSendStatus::printHeader(FILE* fp, int, fxBool showHost)
  90. {
  91.     fprintf(fp, "%-4s %-5s %-15s %-16s %-14s",
  92.     "Job", "Modem", "Destination", "Time-To-Send", "Sender");
  93.     if (showHost)
  94.     fprintf(fp, " %-10s", "Host");
  95.     fprintf(fp, " Status\n");
  96. }
  97.  
  98. void
  99. FaxSendStatus::print(FILE* fp, int ncols, fxBool showHost)
  100. {
  101.     fprintf(fp, "%-4s %-5s %-15.15s"
  102.     , (char*) jobname
  103.     , (char*) modem
  104.     , (char*) number
  105.     );
  106.     if (!isSendAt) {
  107.     fprintf(fp, " %5.5s %10.10s"
  108.         , (isLocked || tts == "asap" ? "" : (char*) tts)
  109.         , (isLocked || tts == "asap" ? "" : (char*) dts)
  110.     );
  111.     } else
  112.     fprintf(fp, " %-16.16s" , (char*) tts);
  113.     fprintf(fp, " %-14.14s", (char*) sender);
  114.     ncols -= 59;
  115.     if (showHost) {
  116.     fprintf(fp, " %-10.10s", (char*) host);
  117.     ncols -= 11;
  118.     }
  119.     if (ncols < 10)
  120.     ncols = 10;
  121.     if (status.length() > ncols-1)
  122.     fprintf(fp, " %.*s...\n", ncols-4, (char*) status);
  123.     else
  124.     fprintf(fp, " %s\n", (char*) status);
  125. }
  126.  
  127. FaxSendAtStatus::FaxSendAtStatus()
  128. {
  129.    isLocked = FALSE;
  130.    isSendAt = TRUE;
  131. }
  132. FaxSendAtStatus::~FaxSendAtStatus() {}
  133.  
  134. fxIMPLEMENT_ObjArray(FaxSendStatusArray, FaxSendStatus);
  135.